package com.lihaogn.sell.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @FileName: MyWebMvcConfig
 * @Description: TODO
 * @Author: lihao
 * @Date: 2019-05-14 09:23
 * @Version: 1.0
 */
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedHeaders("*")
                .allowedMethods("*")
                .maxAge(1800)
                .allowedOrigins("*");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 添加静态资源访问路径
//        registry.addResourceHandler("/pic/**").addResourceLocations("file:D:/softwareData/SellMs/pic/food/");
//        registry.addResourceHandler("/carousel/**").addResourceLocations("file:D:/softwareData/SellMs/pic/slide/");

        // prod-linux上的环境
        registry.addResourceHandler("/pic/**").addResourceLocations("file:/home/webapp/document/sell-pic/food-pic/");
        registry.addResourceHandler("/carousel/**").addResourceLocations("file:/home/webapp/document/sell-pic/slide-show/");
    }
}
